package com.basketball.gym.pojo;

import com.baomidou.mybatisplus.annotation.IdType;

import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * <p>
 *
 * </p>
 *
 * @author 赵肖云
 * @since 2021-03-23
 */
@Data
@ApiModel(value = "Admin", description = "管理员对象")
public class Admin implements Serializable {
    public interface login {
    }

    public interface addAdmin {
    }

    public interface update {
    }

    @ApiModelProperty(value = "用户状态")
    private Integer state;

    @ApiModelProperty(value = "头像")
    private String avatarUrl;

    @ApiModelProperty(value = "姓名")
    private String name;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "注册时间")
    private LocalDateTime createAt;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updateAt;

    @ApiModelProperty(value = "手机号")
    private String phone;

    @ApiModelProperty(value = "管理员ID")
    @TableId(value = "id", type = IdType.AUTO)
    @NotNull(message = "id不能为空", groups = {update.class})
    private Integer id;

    @JsonBackReference("密码")
    @NotNull(message = "密码不能为空", groups = {login.class, addAdmin.class})
    @ApiModelProperty(value = "密码")
    private String password;

    @NotNull(message = "用户名不能为空", groups = {login.class, addAdmin.class})
    @ApiModelProperty(value = "用户名")
    private String userName;

    @NotNull(message = "roleId不能为空", groups = {addAdmin.class})
    @Min(value = 2, message = "roleId只能为2或3", groups = {addAdmin.class, update.class})
    @Max(value = 3, message = "roleId只能为2或3", groups = {addAdmin.class, update.class})
    @ApiModelProperty(value = "角色ID")
    private Integer roleId;

    @TableField(exist = false)
    @ApiModelProperty(value = "角色")
    private String role;

    @TableField(exist = false)
    @JsonBackReference("当前页")
    @ApiModelProperty("当前页")
    private Integer current;

    @TableField(exist = false)
    @JsonBackReference("每页条数")
    @ApiModelProperty("每页条数")
    private Integer size;

    public Admin() {
    }

    public Admin(Integer id) {
        this.id = id;
    }

    public Admin(Integer id, String role) {
        this.id = id;
        this.role = role;
    }

    public void setRole() {
        if (roleId == 2) {
            role = "admin";
        } else if (roleId == 3) {
            role = "superAdmin";
        }
    }
}
